notebook: use the current state to get the padding values
authorCosimo Cecchi <cosimoc@gnome.org>
Tue, 27 Sep 2011 16:54:22 +0000 (12:54 -0400)
committerCosimo Cecchi <cosimoc@gnome.org>
Tue, 27 Sep 2011 17:43:21 +0000 (13:43 -0400)
We want to enable the use of different padding values between active and
inactive tabs, so that the two are completely separated (but limited by
the active tab size).
This way themes can decide how bigger the active tab is drawn compared
to the normal one just specifying a different padding value from the
CSS, like this:

.notebook tab {
  padding: 2;
}

.notebook tab:active {
  padding: 4;
}

As a first step, fetch the padding values with the right state flags
from GtkStyleContext.

https://bugzilla.gnome.org/show_bug.cgi?id=659777

gtk/gtknotebook.c

index 8ea2c6c9aa706388da477944667a51318a4000f2..8ca365248cdcf191647ed923d2c500e0c29fbdfc 100644 (file)
@@ -2008,6 +2008,7 @@ gtk_notebook_get_preferred_tabs_size (GtkNotebook    *notebook,
       if (gtk_widget_get_visible (page->child))
         {
           GtkBorder tab_padding;
+          GtkStateFlags state;
 
           vis_pages++;
 
@@ -2018,10 +2019,15 @@ gtk_notebook_get_preferred_tabs_size (GtkNotebook    *notebook,
                                          &child_requisition, NULL);
 
           /* Get border/padding for tab */
+          if (page == priv->cur_page)
+            state = GTK_STATE_FLAG_ACTIVE;
+          else
+            state = GTK_STATE_FLAG_NORMAL;
+
           gtk_style_context_save (context);
           gtk_style_context_add_region (context, GTK_STYLE_REGION_TAB,
                                         _gtk_notebook_get_tab_flags (notebook, page));
-          gtk_style_context_get_padding (context, 0, &tab_padding);
+          gtk_style_context_get_padding (context, state, &tab_padding);
           gtk_style_context_restore (context);
 
           page->requisition.width = child_requisition.width +
@@ -6155,6 +6161,7 @@ gtk_notebook_page_allocate (GtkNotebook     *notebook,
   gboolean tab_allocation_changed;
   gboolean was_visible = page->tab_allocated_visible;
   GtkBorder tab_padding;
+  GtkStateFlags state;
 
   if (!page->tab_label ||
       !gtk_widget_get_visible (page->tab_label) ||
@@ -6164,13 +6171,18 @@ gtk_notebook_page_allocate (GtkNotebook     *notebook,
       return was_visible;
     }
 
+  if (page == priv->cur_page)
+    state = GTK_STATE_FLAG_ACTIVE;
+  else
+    state = GTK_STATE_FLAG_NORMAL;
+
   context = gtk_widget_get_style_context (widget);
 
   gtk_style_context_save (context);
   gtk_style_context_add_region (context, GTK_STYLE_REGION_TAB,
                                 _gtk_notebook_get_tab_flags (notebook, page));
 
-  gtk_style_context_get_padding (context, 0, &tab_padding);
+  gtk_style_context_get_padding (context, state, &tab_padding);
 
   gtk_widget_get_preferred_size (page->tab_label, &tab_requisition, NULL);
   gtk_widget_style_get (widget,